<template>
  <div>
      <FormPanel
        ref="from"
        :list="formList"
        :cols="3"
        :labelWidth="110"
        :isSubmitBtn="false"
        @formChange="formChangeHandle"
      />
      <div
        :style="{
          position: 'absolute',
          left: 0,
          bottom: 0,
          right: 0,
          zIndex: 9,
          borderTop: '1px solid #e9e9e9',
          padding: '10px 20px',
          background: '#fff',
          textAlign: 'right'
        }"
      >
        <el-button @click="closeDrawer(1)">关 闭</el-button>
        <!-- <el-button @click="closeDrawer(2)" type="primary">保 存</el-button> -->
        <multiuse-button type="primary" :click="closeDrawer.bind(this, 2)">保 存</multiuse-button>
    </div>
  </div>
</template>

<script>
import {putBrands} from '@/api/omSale/vehicleParameters/vehicleType/index.js'
import { dictionary } from '@/utils/dictMixin';
import Cookies from 'js-cookie';
import moment from 'moment'
export default {
  name: 'BrandaddModal',
  mixins: [dictionary],
  data() {
    this.saveData = null;
    return {
      formList: this.createFormList()
    };
  },
  props:['rowData'],
  created() {
    this.init()
  },
  methods: {
    createFormList() {
      return [
        {
          type: 'INPUT',
          label: '品牌代码',
          fieldName: 'brandCode',
          placeholder: '请输入...',
          rules: [
            { required: true, message: '请输入品牌代码', trigger: 'blur' },

          ]
        },
        {
          type: 'INPUT',
          label: '品牌名称',
          fieldName: 'brandName',
          placeholder: '请输入...',
          rules: [{ required: true, message: '请输入品牌名称', trigger: 'blur' }]
        },
        {
          type: 'SELECT',
          label: '启用标记',
          fieldName: 'isValid',
          placeholder: '请选择',
          itemList: this.createDictList('1004'),
          rules: [{ required: true, message: '请选择', trigger: 'change' }]
        },

        {
          type: 'DATE',
          label: '启用日期',
          fieldName: 'startDate',
          placeholder: '请选择',
          dateType:'exactdate',
          minDateTime:moment().format('YYYY-MM-DD'),
          rules: [{ required: true, message: '请选择', trigger: 'change' }]
        }
      ];
    },
    init(){
      for(let i in this.rowData){
        this.formList.map(x=>{
          if(x.fieldName==i){
            x.initialValue=this.rowData[i];
          }
        })
      }
    },
    formChangeHandle(val) {
      this.saveData = val;
    },
    async closeDrawer(type){
      if(type==1){
        this.$emit('close')
      }else{
        this.$refs.from.SUBMIT_FORM();
        console.log(this.saveData, 'this.saveData');
        if (this.saveData) {
          let json = JSON.parse(JSON.stringify(this.saveData));
          json.brandId=this.rowData.brandId;
          json.recordVersion=this.rowData.recordVersion;
          let res = await putBrands(json);
          if (res.resultCode == 200) {
            this.$notify({
              title: '成功',
              message: '保存成功',
              type: 'success'
            });
            this.$emit('close', json);
          }else{
            this.saveData=null;
          }
        }

      }
    }
  }
};
</script>

<style lang="less" scoped></style>
